import { IDispose } from "../../gengine/core/IDispose";
import { LoaderManager } from "../../gengine/resource/LoaderManager";
import { UICompomentPool } from "../utils/UICompomentPool";
type int = number;
//class GImageBitmap
    
    export  class GImageBitmap /* flash.display.Bitmap */ implements IDispose
    {
        constructor(arg1: string=null, arg2: int=0, arg3: int=0)
        {
            
            this.imgUrl = arg1;
            x = arg2;
            y = arg3;
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStage);
            this.addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStage);
            return;
        }

        /* internal  */onAddToStage(arg1: Object /* flash.events.Event */): void
        {
            return;
        }

        /* internal  */onRemoveFromStage(arg1: Object /* flash.events.Event */): void
        {
            return;
        }

        public set imgUrl(arg1: string)
        {
            if (!arg1) 
            {
                return;
            }
            this._imgUrl = GImageBitmap.getUrl(arg1);
            this.setBitmapdata(this._imgUrl);
            return;
        }

        public get imgUrl(): string
        {
            return this._imgUrl;
        }

        protected setBitmapdata(arg1: string): void
        {
            var url: string;
            var bitmap: Object /* flash.display.Bitmap */;

            var loc1;
            bitmap = null;
            url = arg1;
            bitmap = this;
            LoaderManager.instance.load(url, (arg1): void
            {
                bitmap.bitmapData = arg1.bitmapData as Object /* flash.display.BitmapData */;
                return;
            }, this.loadPriority)
            return;
        }

        public get loadPriority(): int
        {
            return this._loadPriority;
        }

        public set loadPriority(arg1: int)
        {
            this._loadPriority = arg1;
            return;
        }

        public dispose(arg1: Boolean=true): void
        {
            x = 0;
            y = 0;
            this._imgUrl = "";
            this._loadPriority = 3;
            bitmapData = null;
            if (this.parent) 
            {
                this.parent.removeChild(this);
            }
            if (arg1) 
            {
                UICompomentPool.disposeUICompoment(this);
            }
            return;
        }

        public static getUrl(arg1: string): string
        {
            var loc2=null;
            var loc1=arg1.toLocaleLowerCase();
            var loc3=0;
            var loc4=GImageBitmap._arySuffix;
            for(loc2 of loc4) 
            {
                if (!(loc1.indexOf(loc2) > 0)) 
                {
                    continue;
                }
                return arg1;
            }
            return arg1 + ".swf";
        }

        private /* var */_imgUrl: string;

        private /* var */_loadPriority: int=3;

        public static /* var */_arySuffix: Array<any>;
    }

            GImageBitmap._arySuffix = [".png", ".jpg", ".jpeg", ".swf"];
        